package com.shuqi.model.parse.parser;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import com.shuqi.model.parse.HandlerBase;

/**
 * 
 * 验证手机号和验证码的解析器
 * 
 */
public class AccountBindVerifyParser extends HandlerBase {

    private AccountBindByPhoneInfo mInfo;

    private String mPhoneNumber;

    private String mVerifyCode;

    public AccountBindVerifyParser(String phoneNumber, String verifyCode) {
        this.mPhoneNumber = phoneNumber;
        this.mVerifyCode = verifyCode;
    }

    @Override
    public AccountBindByPhoneInfo getParsedData() {
        return mInfo;
    }

    @Override
    public void characters(char[] ch, int start, int length) throws SAXException {}

    @Override
    public void startDocument() throws SAXException {
        mInfo = new AccountBindByPhoneInfo();
        mInfo.phoneNumber = mPhoneNumber;
        mInfo.verifyCode = mVerifyCode;
    }

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attrs)
            throws SAXException {
        if (localName.equals("serverinfo")) {
            String code = attrs.getValue("state");
            String msg = attrs.getValue("message");
            mInfo.state = code;
            mInfo.msg = msg;
        }
    }

    @Override
    public void endDocument() throws SAXException {
        super.endDocument();
    }

    public static class AccountBindByPhoneInfo {

        public String state;

        public String msg;

        public String phoneNumber;

        public String verifyCode;
    }
}
